package com.frejoys.app.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.common.PageDto;
import com.frejoys.common.enums.EUserRole;
import com.frejoys.common.error.HttpStatus;
import com.frejoys.common.exception.GeneralException;
import com.frejoys.common.response.Result;
import com.frejoys.common.util.CommonUtil;
import com.frejoys.common.util.RequestUtil;
import com.frejoys.common.vo.app.UserLevelVo;
import com.frejoys.dao.entity.User;
import com.frejoys.dao.entity.UserLevelAgent;
import com.frejoys.service.UserLevelAgentService;
import com.frejoys.service.UserLevelPromotionService;
import com.frejoys.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "级层", description = "级层")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixApp)
@Authorization(Authority.Private)
public class UserPromotionController {

    private final UserLevelPromotionService userPromotionService;

    private final UserLevelAgentService userLevelAgentService;

    private final UserService userService;

//    @PostMapping("/userPromotion/oneUserPromotionInfo")
//    @Operation(summary = "用户推广一级信息列表")
//    public Result<List<UserLevelVo>> oneUserPromotionInfo(@RequestBody @Validated PageDto dto){
//
//        User user = userService.getInfo(RequestUtil.userId());
//        List<UserLevelVo> list = new ArrayList<>();
//
//        if (CommonUtil.bitExistOffset(user.getRole(), EUserRole.promotion.getValue())){
//
//            list = userPromotionService.oneUserPromotionInfo(RequestUtil.userId(),dto);
//        }else if (CommonUtil.bitExistOffset(user.getRole(), EUserRole.agent.getValue())){
//
//            list = userLevelAgentService.oneUserAgentInfo(RequestUtil.userId(),dto);
//        }
//        return Result.success(list);
//    }
//
//    @PostMapping("/userPromotion/twoUserPromotionInfo")
//    @Operation(summary = "用户推广二级信息列表")
//    public Result<List<UserLevelVo>> twoUserPromotionInfo(@RequestBody @Validated PageDto dto){
//
//        User user = userService.getInfo(RequestUtil.userId());
//        List<UserLevelVo> list = new ArrayList<>();
//
//        if (CommonUtil.bitExistOffset(user.getRole(), EUserRole.promotion.getValue())){
//
//            list = userPromotionService.twoUserPromotionInfo(RequestUtil.userId(),dto);
//
//        }else if (CommonUtil.bitExistOffset(user.getRole(), EUserRole.agent.getValue())){
//
//            list = userLevelAgentService.twoUserAgentInfo(RequestUtil.userId(),dto);
//        }
//
//        return Result.success(list);
//    }
}
